﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using sydfdl.TMS.BLL;
using sydfdl.TMS.Model;
using sydfdl.TMS.Tool;

namespace sydfdl.TMS.Areas.SystemData.Controllers
{
    public class CityController : Controller
    {
        //
        // GET: /SystemData/City/

        public ActionResult Index()
        {
            return View();
        }

        public void Get()
        {
            Response.Write(JsonHelp.EntitiesToString(new BLLT_B_City().GetList()));
        }

        public void Save()
        {
            string json = @"[]";
            IEnumerable<T_B_City> add = Request.Form.Get("add") == json ? null : JsonHelp.ConvertJsonToEntity<IEnumerable<T_B_City>>(Request.Form.Get("add"));
            IEnumerable<T_B_City> edit = Request.Form.Get("edit") == json ? null : JsonHelp.ConvertJsonToEntity<IEnumerable<T_B_City>>(Request.Form.Get("edit"));
            IEnumerable<T_B_City> del = Request.Form.Get("del") == json ? null : JsonHelp.ConvertJsonToEntity<IEnumerable<T_B_City>>(Request.Form.Get("del"));
            if (add != null)
                add.ToList().ForEach(a =>
                {
                    a.YID = Guid.NewGuid();
                    add.Where(b => b._pid == a._id).ToList().ForEach(c =>
                    {
                        c.FID = a.YID;
                    });
                });

            Response.Write(new BLLT_B_City().Save(add, edit, del));
        }

    }
}
